{% extends "scheduling/base.html" %}
{% load static %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2><i class="fas fa-bus me-2"></i>车辆管理</h2>
        <a href="{% url 'add_bus' %}" class="btn btn-primary">
            <i class="fas fa-plus-circle me-2"></i>添加车辆
        </a>
    </div>

    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-striped table-hover">
                    <thead class="table-light">
                        <tr>
                            <th>车牌号</th>
                            <th>车型</th>
                            <th>核载人数</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for bus in buses %}
                        <tr>
                            <td>{{ bus.bus_id }}</td>
                            <td>{{ bus.model.name }}</td>
                            <td>{{ bus.capacity }}人</td>
                            <td>
                                {% if bus.status == 'normal' %}
                                <span class="badge bg-success">正常</span>
                                {% else %}
                                <span class="badge bg-warning">维修</span>
                                {% endif %}
                            </td>
                            <td>
                                <a href="{% url 'edit_bus' bus_id=bus.bus_id %}" class="btn btn-sm btn-outline-primary">
                                    <i class="fas fa-edit"></i> 编辑
                                </a>
                                <form action="{% url 'delete_bus' bus_id=bus.bus_id %}" method="post" style="display: inline;">
                                    {% csrf_token %}
                                    <button type="submit" class="btn btn-sm btn-outline-danger">
                                        <i class="fas fa-trash-alt"></i> 删除
                                    </button>
                                </form>
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="5" class="text-center py-4">暂无车辆数据</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}
